rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Lv Gongzhu's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_lv,vertex.cex=rescale(deg,0.5,3))
par(op)
library('maps')
library('geosphere')
library(maptools)
library(foreign)
library(PBSmapping)
library(network)
library(maps)
library(statnet)
require(rgdal)
song <- importShapefile("songprovinces1080_gr8.shp")
proj.abbr <- attr(song, "projection")
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Wang Anshi's kinship network (Figure 1 (a))#
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="black",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='black',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Lv Gongzhu's kinship network (Figure 1 (b))#
plot.network(net_lv,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_lv%v%"lon",net_lv%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.cex=rescale(deg,1,4),
vertex.col="black",
vertex.border='black',
edge.col="grey",
#usecurve=TRUE,
#edge.curve = 0.001,
# please don't jitter the points around
jitter=FALSE)
rm(list = ls())
library(igraph)
library(statnet)
library("network")
#Change this to your local directory#
setwd("/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Chapter 5/data/")
#read in egelist
rawedgeswang<-read.csv("Wang Anshi edgelist.csv")
#turn edgelist into adjacency matrix
matrixwang <-as.matrix(get.adjacency(graph.data.frame(rawedgeswang)))
#write in a csv file
write.csv(matrixwang,"Wang Anshi adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.wang <- as.matrix(matrixwang)
# load in vertex attributes
#orignal coordinates
nodeInfoWANG <- read.csv(file="Wang node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.wang) # peek at matrix
print(nodeInfoWANG)  # peek at attribute data
# create undirected network object from matrix
net_wang<-network(net.adj.wang, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_wang)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_wang%v%"lon" <- nodeInfoWANG$x
net_wang%v%"lat" <- nodeInfoWANG$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_wang)
summary(net_wang)
gden(net_wang)
degwang <- degree(net_wang,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Wang Anshi's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_wang,vertex.cex=rescale(degwang,0.5,3))
par(op)
###############################
#Lv Gongzhu's kinship network#
##############################
library(igraph)
library(statnet)
library("network")
#Change this to your local directory#
setwd("/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Chapter 5/data/")
#read in egelist
rawedgeslv<-read.csv("Lv Gongzhu edgelist.csv")
#turn edgelist into adjacency matrix
matrixlv <-as.matrix(get.adjacency(graph.data.frame(rawedgeslv)))
#write in a csv file
write.csv(matrixlv,"Lv Gongzhu adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.lv <- as.matrix(matrixlv)
# load in vertex attributes
#orignal coordinates
nodeInfoLV <- read.csv(file="Lv node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.lv) # peek at matrix
print(nodeInfoLV)  # peek at attribute data
# create undirected network object from matrix
net_lv<-network(net.adj.lv, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_lv)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_lv%v%"lon" <- nodeInfoLV$x
net_lv%v%"lat" <- nodeInfoLV$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_lv)
summary(net_lv)
gden(net_lv)
deg <- degree(net_lv,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Lv Gongzhu's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_lv,vertex.cex=rescale(deg,0.5,3))
par(op)
library('maps')
library('geosphere')
library(maptools)
library(foreign)
library(PBSmapping)
library(network)
library(maps)
library(statnet)
require(rgdal)
song <- importShapefile("songprovinces1080_gr8.shp")
proj.abbr <- attr(song, "projection")
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Wang Anshi's kinship network (Figure 1 (a))#
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="black",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='black',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
library('maps')
library('geosphere')
library(maptools)
library(foreign)
library(PBSmapping)
library(network)
library(maps)
library(statnet)
require(rgdal)
song <- importShapefile("songprovinces1080_gr8.shp")
proj.abbr <- attr(song, "projection")
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Wang Anshi's kinship network (Figure 1 (a))#
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="green",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='green',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="darkgreen",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='darkgreen',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Lv Gongzhu's kinship network (Figure 1 (b))#
plot.network(net_lv,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_lv%v%"lon",net_lv%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.cex=rescale(deg,1,4),
vertex.col="red",
vertex.border='red',
edge.col="grey",
#usecurve=TRUE,
#edge.curve = 0.001,
# please don't jitter the points around
jitter=FALSE)
rm(list = ls())
library(igraph)
library(statnet)
library("network")
setwd("/Users/ywang/Dropbox/Book Project on State Building/Wang Anshi reform article/journal submission/apsr/5/replication file/")
#read in egelist
rawedgeswang<-read.csv("Wang Anshi edgelist.csv")
#turn edgelist into adjacency matrix
matrixwang <-as.matrix(get.adjacency(graph.data.frame(rawedgeswang)))
#write in a csv file
write.csv(matrixwang,"Wang Anshi adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.wang <- as.matrix(matrixwang)
# load in vertex attributes
#orignal coordinates
nodeInfoWANG <- read.csv(file="Wang node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.wang) # peek at matrix
print(nodeInfoWANG)  # peek at attribute data
# create undirected network object from matrix
net_wang<-network(net.adj.wang, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_wang)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_wang%v%"lon" <- nodeInfoWANG$x
net_wang%v%"lat" <- nodeInfoWANG$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_wang)
summary(net_wang)
gden(net_wang)
degwang <- degree(net_wang,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Wang Anshi's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_wang,vertex.cex=rescale(degwang,0.5,3))
par(op)
library(igraph)
library(statnet)
library("network")
setwd("/Users/ywang/Dropbox/Book Project on State Building/Wang Anshi reform article/journal submission/apsr/5/replication file/")
#read in egelist
rawedgeslv<-read.csv("Lv Gongzhu edgelist.csv")
#turn edgelist into adjacency matrix
matrixlv <-as.matrix(get.adjacency(graph.data.frame(rawedgeslv)))
#write in a csv file
write.csv(matrixlv,"Lv Gongzhu adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.lv <- as.matrix(matrixlv)
# load in vertex attributes
#orignal coordinates
nodeInfoLV <- read.csv(file="Lv node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.lv) # peek at matrix
print(nodeInfoLV)  # peek at attribute data
# create undirected network object from matrix
net_lv<-network(net.adj.lv, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_lv)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_lv%v%"lon" <- nodeInfoLV$x
net_lv%v%"lat" <- nodeInfoLV$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_lv)
summary(net_lv)
gden(net_lv)
deg <- degree(net_lv,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Lv Gongzhu's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_lv,vertex.cex=rescale(deg,0.5,3))
par(op)
library('maps')
library('geosphere')
library(maptools)
library(foreign)
library(PBSmapping)
library(network)
library(maps)
library(statnet)
require(rgdal)
song <- importShapefile("songprovinces1080_gr8.shp")
proj.abbr <- attr(song, "projection")
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Wang Anshi's kinship network (Figure 1 (a))#
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="black",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='black',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Lv Gongzhu's kinship network (Figure 1 (b))#
plot.network(net_lv,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_lv%v%"lon",net_lv%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.cex=rescale(deg,1,4),
vertex.col="black",
vertex.border='black',
edge.col="grey",
#usecurve=TRUE,
#edge.curve = 0.001,
# please don't jitter the points around
jitter=FALSE)
rm(list = ls())
library(igraph)
library(statnet)
library("network")
#Change this to your local directory#
setwd("/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Chapter 5/data/")
#read in egelist
rawedgeswang<-read.csv("Wang Anshi edgelist.csv")
#turn edgelist into adjacency matrix
matrixwang <-as.matrix(get.adjacency(graph.data.frame(rawedgeswang)))
#write in a csv file
write.csv(matrixwang,"Wang Anshi adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.wang <- as.matrix(matrixwang)
# load in vertex attributes
#orignal coordinates
nodeInfoWANG <- read.csv(file="Wang node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.wang) # peek at matrix
print(nodeInfoWANG)  # peek at attribute data
# create undirected network object from matrix
net_wang<-network(net.adj.wang, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_wang)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_wang%v%"lon" <- nodeInfoWANG$x
net_wang%v%"lat" <- nodeInfoWANG$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_wang)
summary(net_wang)
gden(net_wang)
degwang <- degree(net_wang,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Wang Anshi's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_wang,vertex.cex=rescale(degwang,0.5,3))
par(op)
library(igraph)
library(statnet)
library("network")
#Change this to your local directory#
setwd("/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Chapter 5/data/")
#read in egelist
rawedgeslv<-read.csv("Lv Gongzhu edgelist.csv")
#turn edgelist into adjacency matrix
matrixlv <-as.matrix(get.adjacency(graph.data.frame(rawedgeslv)))
#write in a csv file
write.csv(matrixlv,"Lv Gongzhu adjmatrix.csv", row.names = FALSE)
# detach igraph package
detach("package:igraph")
#Read in Adjacency Matrix
net.adj.lv <- as.matrix(matrixlv)
# load in vertex attributes
#orignal coordinates
nodeInfoLV <- read.csv(file="Lv node attributes.csv",header=TRUE,stringsAsFactors=FALSE)
print(net.adj.lv) # peek at matrix
print(nodeInfoLV)  # peek at attribute data
# create undirected network object from matrix
net_lv<-network(net.adj.lv, directed=FALSE, matrix.type="adjacency")
# it read in vertex names from matrix col names ...
network.vertex.names(net_lv)
# ATTACHING VERTEX ATTRIBUTES
# load in other attributes
net_lv%v%"lon" <- nodeInfoLV$x
net_lv%v%"lat" <- nodeInfoLV$y
# Note: order of attributes in the data frame MUST match vertex ids
# otherwise the attribute will get assigned to the wrong vertex
# check that they got loaded
list.vertex.attributes(net_lv)
summary(net_lv)
gden(net_lv)
deg <- degree(net_lv,gmode="graph")
rescale<-function(nchar,low,high){
min_d<-min(nchar)
max_d<-max(nchar)
rscl<-((high-low)*(nchar-min_d))/(max_d-min_d)+low
rscl
}
#A peek of Lv Gongzhu's kinship network#
op<-par(mar=c(0,0,0,0))
plot(net_lv,vertex.cex=rescale(deg,0.5,3))
par(op)
library('maps')
library('geosphere')
library(maptools)
library(foreign)
library(PBSmapping)
library(network)
library(maps)
library(statnet)
require(rgdal)
song <- importShapefile("songprovinces1080_gr8.shp")
proj.abbr <- attr(song, "projection")
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Wang Anshi's kinship network (Figure 5.2 (a))#
plot.network(net_wang,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_wang%v%"lon",net_wang%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.col="darkgreen",
vertex.cex=rescale(degwang,0.5,3),
vertex.border='darkgreen',
edge.col="grey",
# please don't jitter the points around
jitter=FALSE)
#Creat the Song map#
plotPolys(song, projection=proj.abbr, border="grey",
xlab="", ylab="",col="#f5f5f2", tckLab = FALSE,axes=FALSE)
#Layer on Lv Gongzhu's kinship network (Figure 5.2 (b))#
plot.network(net_lv,  # pass in the network
# don't erase the map before drawing the network
new=FALSE,
# get coordiantes from vertices and pass in as 2-col matrix
coord=cbind(net_lv%v%"lon",net_lv%v%"lat"),
# ---- all the rest of these are optional to make it look nice ------
# set a semi-transparent edge color
vertex.cex=rescale(deg,1,4),
vertex.col="red",
vertex.border='red',
edge.col="grey",
#usecurve=TRUE,
#edge.curve = 0.001,
# please don't jitter the points around
jitter=FALSE)
